package com.neuedu.yyzx.config;

import com.neuedu.yyzx.common.Ret;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 * @author 金山
 * 项目：yyzx
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/268:46
 */
@RestControllerAdvice
public class WholeExceptionControllerAdvice {


    // @ExceptionHandler(value = RuntimeException.class)
    @ExceptionHandler(value = Throwable.class)
    public Ret handlerException(Exception ex) {
        // 打印异常
        // 存储到数据库中
        ex.printStackTrace();

        if (ex instanceof NoHandlerFoundException) {

            return Ret.notFound(ex.getMessage());
        } else {
            return Ret.error(ex.getMessage());
        }


    }


}
